package com.example.demo.order.controller;

import com.alibaba.nacos.client.utils.JSONUtils;
import com.example.demo.consts.ValidateConst;
import com.example.demo.order.domain.dto.TestReqDto;
import com.example.demo.order.domain.dto.TestRespDto;
import com.example.demo.response.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @Auther: miaoguoxin
 * @Date: 2020/3/18 15:34
 * @Description:
 */
@RestController
@RequestMapping("/order")
public class OrderTestController {

    @Value("${server.port}")
    private Integer port;

    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/test")
    public ApiResult<String> getOrderPort(){
        return ApiResult.success(String.format("访问order:%d",port));

        //throw new RuntimeException("远程调用失败");
    }


    @RequestMapping("/test_json")
    public ApiResult<TestRespDto> testJson(){
        TestRespDto testRespDto = new TestRespDto();
        testRespDto.setTime(new Date());
        return ApiResult.success(testRespDto);
    }

    @RequestMapping("/fallbackTest")
    public ApiResult<String> testReqJson(@RequestBody @Validated(value = ValidateConst.AddGroup.class)
                                                      TestReqDto reqDto){
        String contentType = request.getContentType();
        return ApiResult.success("服务调用失败");
    }
}
